define(['app'], function(app) {
	'use strict';

	// 实例化方法
	var factory = function(Http) {
		function get_data_bankList(result) {
			if(false) {
				result = '{"success": true,"msg": "","result":{"bank": [' +
					'{"id": "001","bank_name": "工商银行","bank_no": "1234567890","def_bank": true},' +
					'{"id": "002","bank_name": "上海银行","bank_no": "1234567890","def_bank": false}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		function get_data_bankDelete(result){
			if(false) {
				result = '{"success": true,"msg": "","result": {"id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		function get_data_bankDefault(result){
			if(false) {
				result = '{"success": true,"msg": "","result": {"id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		// 返回信息
		return {
			//银行账号一览
			bank_list: function(nPage,callback,calldone) {
				//post请求
				Http.post({
					method: 'member.bankdata.getlist',
					pagelimit: 10,
					nPage: nPage
				}, function(result) {
					//函数回调
					if(callback)
						callback(get_data_bankList(result).result);
				}, function(e) {
					
				}, function() {
					if(calldone)
					calldone();
				});
			},
			//银行账号删除
			bank_delete: function(id,callback) {
				Http.post({
					method: 'member.bankdata.delete',
					id: id
				}, function(reslut) {
					if(callback)
					callback(get_data_bankDelete(reslut));
				}, function(e) {

				}, function() {

				})
			},
			//银行账号详细信息
			bank_detail: function(id,callback) {
				Http.post({
					method: 'member.bankdata.detail',
					id: id
				}, function(result) {

				}, function(e) {

				}, function() {

				})
			},
			//默认银行账号
			bank_default: function(id,callback) {
				Http.post({
					method: 'member.bankdata.setdefault',
					id: id
				}, function(result) {
					if(callback)
					callback(get_data_bankDefault(result));
				}, function(e) {

				}, function() {

				})
			}
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Banklist", factory);
});